package com.commerce.common.utils;

import com.commerce.common.entity.User;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import java.util.List;

/**
 * 分页结果类
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageResult<T> {
    private List<T> content;
    private long totalElements;
    private int totalPages;
    private int page;
    private int size;

    public PageResult(long totalElements, List<T> content) {
        this.totalElements = totalElements;
        this.content = content;
    }

    public PageResult(List<T> records, long total, long size, long current) {
        this.totalElements = total;
        this.content = records;
        this.page = (int) current;
        this.size = (int) size;
        this.totalPages = (int) Math.ceil((double) total / size);
    }

    public static <T> PageResult<T> of(List<T> content, long totalElements, int page, int size) {
        PageResult<T> result = new PageResult<>();
        result.setContent(content);
        result.setTotalElements(totalElements);
        result.setPage(page);
        result.setSize(size);
        result.setTotalPages((int) Math.ceil((double) totalElements / size));
        return result;
    }
} 